home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15951 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  66 lines

  1. Newsgroups: comp.lang.c++
  2. Path: newsfeed.internetmci.com!anasaz!duane
  3. From: duane@anasazi.com (Duane Morse)
  4. Subject: Re: HELP - Passing strings to a DLL
  5. Message-ID: <DpKIsu.Gqn@anasazi.com>
  6. Sender: usenet@anasazi.com (News System)
  7. Organization: Anasazi Inc, Phoenix AZ USA
  8. References: <4kbbh2$r3c@hp_open.open.org>
  9. Date: Tue, 9 Apr 1996 00:02:43 GMT
  10.  
  11. THayworth@open.org (Tina Hayworth) writes:
  12.  
  13. >I am not an experienced C++ programmer, but I have taken a couple C 
  14. >classes a few years ago.  I need to write a simple DLL that will be called by 
  15. >VB.
  16.  
  17. >I found some sample code, wrote the program, and it worked - I thought I had 
  18. >it all figured out. But if I try passing a pointer to a large string to a 
  19. >function in the DLL, I get a GPF.
  20.  
  21. >In the code below, if commarea is 40 bytes or less it works.  If it is larger 
  22. >I get a GPF.  The actual string I need to pass is 11,452 bytes.
  23.  
  24. >Can anyone tell me what I am doing wrong?
  25.  
  26. >Here is the function I am calling:
  27.  
  28. >int FAR PASCAL EciSync (char server[], char userid[], char passwd[],
  29. >                        char program[], char transid[], char *commarea, int 
  30. >comsize)
  31. >---------------------------------------------------------------------------
  32. >Here is my DEF file:
  33.  
  34. >LIBRARY  ECIDLLL
  35.  
  36. >EXETYPE WINDOWS 
  37.  
  38. >SEGMENTS
  39. >        WEPSEG      PRELOAD FIXED
  40.  
  41. >CODE    PRELOAD MOVEABLE DISCARDABLE
  42. >DATA    PRELOAD MOVEABLE SINGLE
  43.  
  44. >HEAPSIZE 5120
  45.  
  46. >EXPORTS
  47. >        WEP             @1     RESIDENTNAME
  48. >        EciSync         @2
  49. >------------------------------------------------------------------------
  50. >Here is the Declaration in VB:
  51.  
  52. >Declare Sub EciSync Lib "ecidll.dll" (ByVal S As String, ByVal U As String, 
  53. >ByVal P As String, ByVal Pg As String, ByVal T As String, ByVal c As String, 
  54. >ByVal S As Integer)                                                      
  55.  
  56. I presume your DLL is returning data in commarea (c above).  Did you
  57. preallocate the maximum amount of space that you might write into
  58. this area; for instance, Dim CommArea as String * 12000?  Also,
  59. if you want to use this as a real VB string, EciSync should return
  60. the length of the string, so your calling routine can then do a
  61. Left(c, nLen) to extract the string.
  62. -- 
  63.  
  64. Duane Morse    e-mail: duane@anasazi.com
  65. (602) 861-7609; Phoenix, Arizona
  66.